home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d7 / dvexec.arc / DVEXEC.ASM next >
Assembly Source File  |  1989-03-11  |  6KB  |  255 lines

  1. include dvapi.inc
  2.  
  3. comment * =================================================================
  4.  
  5.         Copyright (C) 1989 George A. Stanislav
  6.         All Rights Reserved
  7.  
  8.         Purpose: Open a DESQview window and execute a task defined by
  9.                  a PIF file passed on the command line tail.
  10.  
  11. * =========================================================================
  12.  
  13. prog    segment para public 'CODE'
  14.  
  15.         assume  cs:prog, ds:prog, es:prog, ss:prog
  16.  
  17.         org     100h    ; Make it a .COM program
  18.  
  19. dvexec  proc    near
  20.  
  21. ; Initialize the program: Make it use only 2 K memory for itself.
  22.  
  23.         mov     ax, 2044
  24.         mov     sp, ax          ; Shrink program size to bear minimum
  25.         push    ds
  26.         pop     es
  27.         mov     bx, 128         ; Release unneeded memory
  28.         mov     ah, 4ah
  29.         int     21h
  30.  
  31. ; Print Copyright notice
  32.  
  33.         lea     dx, copr
  34.         mov     ah, 9
  35.         int     21h
  36.  
  37. ; Check if DESQview is present
  38.  
  39.         @call   dvpresent       ; Use DVAPI.INC macro
  40.         test    ax, ax
  41.         jz      $noDV           ; DESQview not installed
  42.  
  43. ; Parse command line
  44.  
  45.         mov     bx, 80h
  46.         mov     cl, [bx]        ; command line length
  47.         or      cl, cl          ; anything there?
  48.         jz      $noCL           ; nope
  49.  
  50.         sub     ch, ch
  51.         inc     cx              ; command line tail size
  52. $blanks:
  53.         inc     bx              ; next byte
  54.         mov     al, [bx]
  55.         cmp     al, ' '         ; junk?
  56.         ja      $line
  57.         loop    $blanks
  58.  
  59. ; Nothing but junk on command line, exit:
  60.  
  61.         jmp     short $noCL
  62.  
  63. $line:
  64.         mov     word ptr CL_start, bx
  65. $line1:
  66.         cmp     al, ' '         ; end of string?
  67.         jbe     $endline
  68.  
  69.         cmp     al, 'a'         ; lower case char?
  70.         jb      $line2
  71.  
  72.         cmp     al, 'z'
  73.         ja      $line2
  74.  
  75.         sub     al, 32          ; convert to upper case
  76.         mov     [bx], al
  77.  
  78. $line2:
  79.         inc     bx              ; next char
  80.         mov     al, [bx]
  81.         loop    $line1
  82.  
  83. $endline:
  84.         mov     al, 0
  85.         mov     [bx], al        ; Create an ASCIIZ string
  86.         mov     word ptr CL_end, bx
  87.  
  88. ; Open file
  89.  
  90.         mov     ax, 3d00h
  91.         mov     dx, word ptr CL_start
  92.         int     21h
  93.         jc      $badOpen
  94.  
  95. ; Read PIF file to buffer
  96.  
  97.         push    ax              ; Save handle for closing
  98.         mov     bx, ax
  99.         mov     cx, 500         ; a little extra size
  100.         mov     ah, 3fh
  101.         lea     dx, pif
  102.         int     21h
  103.  
  104.         jc      $badRead
  105.  
  106. ; Call DESQview to run new process
  107.  
  108.         mov     bx, ax          ; number of bytes actually read
  109.         lea     di, pif
  110.         @call   newproc
  111.         mov     word ptr task, bx
  112.  
  113. ; Close PIF file
  114.  
  115.         pop     bx              ; Restore file handle
  116.         mov     ah, 3eh
  117.         int     21h
  118.  
  119.         call    success
  120.  
  121. ; Exit with errorlevel 0
  122.  
  123.         mov     ax, 4c00h
  124.         int     21h
  125.  
  126. $noDV:  lea     dx, noDV        ; Print error message
  127. err:    mov     ah, 9
  128.         int     21h
  129.  
  130.         mov     ax, 4c01h       ; Exit with errorlevel 1
  131.         int     21h
  132.  
  133. $noCL:  lea     dx, noCL
  134.         jmp     err
  135. $badOpen:
  136.         lea     dx, badOpen
  137. err1:   mov     ah, 9
  138.         int     21h
  139.  
  140.         mov     bx, CL_end
  141.         mov     al, '$'
  142.         mov     [bx], al
  143.         mov     dx, CL_start
  144.         jmp     err
  145. $badRead:
  146.         lea     dx, badRead
  147.         jmp     err1
  148.  
  149. ; Data:
  150.  
  151.         even
  152.  
  153. task    dw      0
  154. CL_start dw     0
  155. CL_end  dw      0
  156. copr    db      13, 'DVEXEC - version 02-Mar-1989', 13, 10
  157.         db      'Copyright (C) George A. Stanislav', 13, 10
  158.         db      'All rights reserved', 13, 10, 10
  159.         db      '$'
  160. noDV    db      'DESQview not loaded.', 13, 10, '$'
  161. noCL    db      'No PIF specified.', 13, 10, '$'
  162. badOpen db      'Can''t open $'
  163. badRead db      'Can''t read $'
  164. OKmsg   db      'Running $'
  165. taskstr db      13, 10, 'with task handle $'
  166. done    db      '.', 13, 10, '$'
  167. dverror db      'DESQview couldn''t run $'
  168.  
  169. dvexec  endp
  170.  
  171. taskno  proc    near
  172.  
  173. ; Print out task number, followed by a period, cr, and lf.
  174.  
  175.         sub     ax, ax          ; End of string marker
  176.         push    ax
  177.  
  178.         mov     ax, task
  179. $tloop:
  180.         sub     dx, dx
  181.         mov     bx, 10          ; decimal system
  182.         div     bx
  183.         add     dl, '0'         ; convert to ASCII
  184.         push    dx
  185.         or      ax, ax          ; more?
  186.         jne     $tloop
  187.  
  188. ; Now pop the chars off the stack and print them
  189.  
  190. $tlp:
  191.         pop     dx
  192.         or      dx, dx          ; end of string?
  193.         je      $tdone
  194.         mov     ah, 2           ; print char
  195.         int     21h
  196.         jmp     $tlp
  197.  
  198. $tdone:
  199.         lea     dx, done        ; Print dot, cr, lf
  200.         mov     ah, 9
  201.         int     21h
  202.  
  203.         ret                     ; Return to caller
  204.  
  205. taskno  endp
  206.         
  207. success proc    near
  208.  
  209.         mov     bx, task
  210.         or      bx, bx          ; did we succeed?
  211.         jne     $suc
  212.         lea     dx, dverror     ; no handle, failure
  213.         mov     ah, 9
  214.         int     21h
  215.  
  216.         call    taskname
  217.  
  218.         mov     ax, 4c02h       ; exit with errorlevel 2
  219.         int     21h
  220.  
  221. $suc:   lea     dx, OKmsg       ; Announce success
  222.         mov     ah, 9
  223.         int     21h
  224.  
  225.         call    taskname
  226.  
  227.         lea     dx, taskstr     ; task string
  228.         mov     ah, 9           ; Print it out
  229.         int     21h
  230.  
  231.         call    taskno          ; Print task number
  232.  
  233.         ret                     ; Return to caller
  234.  
  235. success endp
  236.  
  237. taskname proc   near
  238.  
  239.         lea     dx, pif[2]      ; Get process name
  240.         mov     bx, 1           ; Standard output - redirectable
  241.         mov     cx, 30          ; Name can be up to 30 bytes long
  242.         mov     ah, 40h
  243.         int     21h             ; Print it out
  244.  
  245.         ret                     ; return to caller
  246.  
  247. taskname endp
  248.  
  249. pif:
  250.  
  251. prog    ends
  252.         end     dvexec
  253.  
  254.  
  255.